# 测试AI解析API
$uri = "http://localhost:5000/api/ai/smart-parse"
$body = @{
    text = "今天下午1点15分开财务现金流讨论会"
} | ConvertTo-Json

$headers = @{
    "Content-Type" = "application/json"
}

try {
    Write-Host "🧪 测试AI智能解析API..." -ForegroundColor Yellow
    Write-Host "📝 测试文本: 今天下午1点15分开财务现金流讨论会" -ForegroundColor Cyan
    
    $response = Invoke-RestMethod -Uri $uri -Method POST -Body $body -Headers $headers
    
    Write-Host "✅ API响应成功!" -ForegroundColor Green
    Write-Host "📊 解析结果:" -ForegroundColor Green
    $response | ConvertTo-Json -Depth 10 | Write-Host
    
} catch {
    Write-Host "❌ API调用失败:" -ForegroundColor Red
    Write-Host $_.Exception.Message -ForegroundColor Red
    
    if ($_.Exception.Message -like "*ConnectFailure*") {
        Write-Host ""
        Write-Host "💡 可能的原因:" -ForegroundColor Yellow
        Write-Host "1. 后端服务未启动 (请运行: npm run dev)" -ForegroundColor Yellow
        Write-Host "2. 端口5000被占用" -ForegroundColor Yellow
    }
    
    if ($_.Exception.Message -like "*OpenAI*" -or $_.Exception.Message -like "*API*") {
        Write-Host ""
        Write-Host "🔑 OpenAI配置问题:" -ForegroundColor Yellow
        Write-Host "1. 检查.env文件是否存在" -ForegroundColor Yellow
        Write-Host "2. 检查OPENAI_API_KEY是否正确配置" -ForegroundColor Yellow
        Write-Host "3. 查看OPENAI_SETUP.md了解配置方法" -ForegroundColor Yellow
    }
}
